<template>
	<view class="cbody">
  <!-- <view class="bigtitle">{{showlist?.title}}</view> -->
	  <rich-text v-if="typeCode==='news'" :nodes="showlist?.content"></rich-text>
	  <image v-if="typeCode==='pic'" v-for="(item,index) in showlist.pic" :src="item" class="imgclass" mode="aspectFill"></image>
  </view>
</template>

<script setup>
	import { onShow ,onLoad} from "@dcloudio/uni-app";
	import { fetchNews,fetchPic,fetchNewsDetail,fetchPicDetail } from "@/utils/api/info";
	import { ref,watch } from 'vue'
	const props = defineProps({
	  dictionary: {
		type: String,
		default: () => '',
	  },
	  typeCode: {
		type: String,
		default: () => '',
	  },
	  id: {
		type: Number,
		default: () => 0,
	  },
	})
	watch(() => props.id, () => {
		props.typeCode==='pic'?getPic():props.typeCode==='news'?getNews():''
	}, {immediate: true});
	const showlist = ref({})
	onLoad(async () => {
		// if(props.id){
		// 	props.typeCode==='pic'?getPic():props.typeCode==='news'?getNews():''
		// 	console.log(2222)
		// }else{
		// 	console.log(1111)
		// }
	});
	//新闻
	const getNews = async() => {
		// let params = {
		// 	pageNum: 1,
		// 	pageSize: 999,
		// 	typeCode: props.typeCode,
		// 	query: {
		// 		dictionary: props.dictionary
		// 	}
		// }
		// console.log(props.id,'qqq')
		// const {data} = await fetchNews(params);
		// showlist.value = data.list.filter((item,index)=>{
		// 	return props.id === item.id
		// })[0]
		let params = {
			id: props.id
		}
		const {data} = await fetchNewsDetail(params);
		showlist.value = data
		console.log(showlist.value,"showlist.value")
	}
	//图片
	const getPic = async() => {
		// let params = {
		// 	pageNum: 1,
		// 	pageSize: 999,
		// 	typeCode: props.typeCode,
		// 	query: {
		// 		dictionary: props.dictionary
		// 	}
		// }
		// const {data} = await fetchPic(params);
		// showlist.value = data.list.filter((item,index)=>{
		// 	return props.id === item.id
		// })[0]
		// showlist.value.pic = showlist.value?.pic.split(',')
		let params = {
			id: props.id
		}
		const {data} = await fetchPicDetail(params);
		showlist.value = data
		showlist.value.pic = showlist.value?.pic.split(',')
		console.log(showlist.value,"showlist.value")
	}

</script>
<style lang="scss" scoped>
	.cbody{
		padding: 20rpx;
	}
.imgclass{
	width: 100%;
	margin-bottom: 20rpx;
	border-radius: 10rpx;
}
</style>

